#!/bin/sh

# function getdir() {
#     for element in $(ls $1); do
#         dir_or_file=$1"/"$element
#         if [ -d $dir_or_file ]; then
#             getdir $dir_or_file
#         else
#             echo $dir_or_file
#         fi
#     done
# }
# echo "GOT POST!"
PAGE_PATH=${HEXO_PATH}/${BLOG_DIR}/source/_posts
# BLOG_PATH='/hexo/blog'

echo "Start deployment"
cd $SOURCE_DIR
echo "Pulling source pages..."
for repo in $(cat repos.txt); do
    cd $repo
    echo "git pull $repo"
    git pull
    cp -f *.md $PAGE_PATH
done
# ln * ${PAGE_PATH}
echo "Update finished."
cd ${HEXO_PATH}/${BLOG_DIR}
hexo clean
hexo g -d
echo "Finished!"
